#ifndef SINGLETON_SCOPED_MUTEX_H
#define SINGLETON_SCOPED_MUTEX_H

#include <pthread.h>
//This mutex is for singleton init, avoid global object init dependency

static pthread_mutex_t _mutex = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP;

/**
 * use for singleton, avoid global var dependency
 */
class SingletonScopedMutex{
public:
    SingletonScopedMutex(){
        pthread_mutex_lock(&_mutex);
    }

    ~SingletonScopedMutex(){
        pthread_mutex_unlock(&_mutex);
    }
};

#endif // SINGLETON_SCOPED_MUTEX_H
